<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>二维码打印</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->
    <script src="/quanliadmin/docroot/js/createreoprt.js"></script>
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form method="post" class="form-inline"  id="search_form" action="/invokingAjax-backend/production/productPrintCode.ajax?operFlg=1" target="_blank">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">

                                     <span>
                                       配送城市：<select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                             <option value="" selected="">请选择</option>                                            　　
                                         </select>
                                    </span>

                                    <span>
                                        配送站：
                                        <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <span>配送日期：<input type="text" class="form-control input-sm" readonly style="width:90px" value="<!--{$send_date|default:''}-->" name="send_date" id="send_date"></span>

                                </td>
                            </tr>

                            <tr>
                                <td height="27px">
                                    <span>订单号：<input type="text" class="form-control input-sm" style="width:110px" value="" name="bill_code" id="bill_code"></span>
                                    <span><input type="button" onclick="bill_goods.search();" class="btn btn-primary" value="查询"></span>
                                    <span><input type="button" onclick="bill_goods.brandPrintCheck();" class="btn btn-warning" value="打印二维码"></span>

                                <td/>

                            <tr/>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
            <input type="hidden" id="test"/>
            <table id="flex" style="display:none;"></table>

        </div>

</div>
<script type="text/javascript">

    $('#send_date').datepicker();
    CreateReport("Report");

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/production/productPrintCode.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "<input type=\"checkbox\" name=\"check_all\" onclick=\"CheckAll();\" id=\"check_all\" >", width : 100, align: "center"},
            {display: "订单编号", width : 140, align: "center"},
            {display: "配送日期", width : 140, align: "center"}

        ],

        sortname: "send_date",
        sortorder: "desc",
        usepager: true,
        rp: 50,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var bill_goods = {
        general_goods:{ },

        //头部 按条件查询
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },
        //获取打印的行数
        brandPrintCheck:function( ) {

            var count=0;
            var check_ids = document.getElementsByName("check_id");
            for(var i=0; i<check_ids.length; i++){
                if(check_ids[i].checked){
                    var bill_code=check_ids[i].id.replace("Checked_","");
                    bill_goods.general_goods[i] = {
                        bill_code : bill_code
                    }
                    count++;
                }
            }
            if(count==0){
                E.alert("请选择要打印的订单");
            }else{
                E.confirm('您确认要打印选中的订单吗？',function(){

                    //调用插件打印二维码
                    Report.LoadFromURL('/report/EWM.grf?v=' + E.createGuid());
                    $.each(bill_goods.general_goods, function(k, v) {
                        Report.LoadDataFromURL('/report/print_ewm.php?bill_code=' + v.bill_code);
                        Report.Print(false);
                    });
                    E.alert(o.message, 3, 'bill_goods.search()');

                   /* Report.LoadFromURL('/report/EWM.grf?v=' + Math.floor(Math.random() * ( 1000 + 1)));
                    $.each(bill_goods.general_goods, function(k, v) {
                        Report.LoadDataFromURL('/report/print_ewm.php?bill_code=' + v.bill_code);
                        Report.PrintPreview(true);
                    });*/

                });

            }
        },


        //重新加载
        load: function() {
            $("#flex").flexReload();
        }


    };

    $(window).ready(function() {

        $("#cityID").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    $.each(result_obj.data, function(i,val){
                        cityHtml +='<option value="'+val.id+'">'+val.name+'</option>';
                    });
                    $('#cityID').html(cityHtml);
                }else{
                    E.alert(result_obj.message);
                }
            }
        });

        //点击城市联动获得配送站(联动)
        $(document).on('change', '#cityID', function() {

            $('#distribution_id').html("");

            var cityID = $('#cityID').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            E.ajax_post({
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                data: {deliver_cityid: cityID},
                call: function( obj ) {
                    if(obj.code ==200 && obj.data != null){

                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                    }else{

                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                    }
                }
            });
        });
    });

    //全选
    function CheckAll(){
        var state = true;
        var textCheck = document.getElementById("test").value;
        if(textCheck=="0"){
            state = false;
            document.getElementById("test").value="1";
        }else{
            document.getElementById("test").value="0";
        }
        var check_ids = document.getElementsByName("check_id");
        for(var i=0; i<check_ids.length; i++){

            if(!check_ids[i].disabled){
                check_ids[i].checked = state;
            }
        }

    }
</script>

</body>
</html>